import 'package:flutter/material.dart';
import 'package:loxen/utils/app_enum_util.dart';
import 'package:loxen/utils/color.dart';
import 'package:loxen/utils/config.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:loxen/utils/string_res.dart';
import 'package:loxen/view/mine/order_list_page.dart';
import 'package:loxen/view/splash_page.dart';
import 'package:loxen/widget/my_subassembly.dart';
import 'package:provider/provider.dart';

class MineOrdersWidget extends StatefulWidget {
  @override
  _MineOrdersWidgetState createState() => _MineOrdersWidgetState();
}

class _MineOrdersWidgetState extends State<MineOrdersWidget> with TickerProviderStateMixin {
  final List<Tab> tabs = [
    Tab(
      text: '  全部  ',
    ),
    Tab(
      text: '待确认',
    ),
    Tab(
      text: '进行中',
    ),
    Tab(
      text: '已完成',
    ),
    Tab(
      text: '已关闭',
    ),
  ];

  final ValueNotifier<int> index = ValueNotifier(0);
  TabController controller;

  @override
  void initState() {
    super.initState();
    controller = TabController(initialIndex: 0, length: tabs.length, vsync: this);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Theme
          .of(context)
          .backgroundColor,
      appBar: PreferredSize(
        preferredSize: Size(double.infinity, 96.h),
        child: Container(
          color: Theme
              .of(context)
              .backgroundColor,
          child: SafeArea(
            child: Column(
              children: [
                Row(
                  children: <Widget>[
                    MySubassembly.getBackIcon(context,
                        color: Theme
                            .of(context)
                            .textTheme
                            .subtitle2
                            .color),
                    Expanded(
                      child: Center(
                        child: Text(
                          StringResources.wo_de_ding_dan,
                          style: TextStyle(
                              fontSize: 32.sp,
                              fontWeight: FontWeight.w500,
                              color: Theme
                                  .of(context)
                                  .textTheme
                                  .subtitle2
                                  .color),
                        ),
                      ),
                    ),
                    MySubassembly.getSearchIcon(null, text: Constants.empty),
                  ],
                ),
                Divider(height: 1.h)
              ],
            ),
          ),
        ),
      ),
      body: Column(
        children: [
          TabBar(
            isScrollable: true,
            onTap: (index) {
              this.index.value = index;
            },
            indicator: UnderlineTabIndicator(
              borderSide: BorderSide(color: Colours.app_main, width: 3.h),
              insets: EdgeInsets.only(right: 40.w,left: 40.w),
            ),
            unselectedLabelColor: Colours.main_text,
            labelColor: Colours.app_main,
            labelStyle: TextStyle(
              fontSize: 29.sp,
              fontWeight: FontWeight.bold,
            ),
            controller: controller,
            tabs: tabs,
          ),
          Expanded(
            child: TabBarView(controller: controller, children: [
              OrderListPage(orderListType: OrderListType.ALL),
              OrderListPage(orderListType: OrderListType.TO_BE_CONFIRMED),
              OrderListPage(orderListType: OrderListType.HAVE_IN_HAND),
              OrderListPage(orderListType: OrderListType.COMPLETED),
              OrderListPage(orderListType: OrderListType.CLOSED),
            ]),
          )
        ],
      ),
    );
  }
}
